You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
874 B
32 lines
874 B
import { requireUser } from "#server/utils/context";
|
|
import { createModel } from "#server/service/llm";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await requireUser(event);
|
|
|
|
const providerId = Number(getRouterParam(event, "providerId"));
|
|
if (!providerId) {
|
|
return R.throwError(400, "无效的供应商ID", null);
|
|
}
|
|
|
|
const body = await readBody(event);
|
|
const { name, modelId, type, enabled, description, maxTokens } = body;
|
|
|
|
if (!name || !modelId) {
|
|
return R.throwError(422, "模型名称和模型ID不能为空", null);
|
|
}
|
|
|
|
const result = await createModel(user.id, {
|
|
providerId,
|
|
name,
|
|
modelId,
|
|
type: type || "text",
|
|
enabled: enabled ?? 1,
|
|
description,
|
|
maxTokens,
|
|
});
|
|
if (!result) {
|
|
return R.throwError(403, "无权操作该供应商", null);
|
|
}
|
|
return R.success(result);
|
|
});
|
|
|